package nc.ui.zzjs.bd.fylx;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;

import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Logger;
import nc.bs.uap.bd.BDRuntimeException;
import nc.itf.uap.IUAPQueryBS;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.ui.trade.pub.IVOTreeDataByID;
import nc.vo.pub.BusinessException;
import nc.vo.pub.SuperVO;
import nc.vo.zzjs.bd.fylx.FylxdocVo;

public class ChnlFylxTreeCardData implements IVOTreeDataByID{
	
	private SuperVO[] m_ChnlManagerVOs = null;

	public String getIDFieldName() {
		return "pk_fylxdoc";
	}

	public String getParentIDFieldName() {
		return "pk_parent";
	}

	public String getShowFieldName() {
		return "vcostname";//vcostname
	}

	public SuperVO[] getTreeVO() {
		if (m_ChnlManagerVOs == null) {
			IUAPQueryBS queryBS = (IUAPQueryBS) NCLocator.getInstance().lookup(IUAPQueryBS.class.getName());
			ArrayList list = null;
			try {
				StringBuffer sql = new StringBuffer() 
				.append(" select a.*")
				.append(" from mcm_fylxdoc a ")
				.append(" where nvl(a.dr,0)=0");
				list = (ArrayList)queryBS.executeQuery(sql.toString(), new BeanListProcessor(FylxdocVo.class));
			} catch (BusinessException e) {
				Logger.error(e.getMessage(), e);
				throw new BDRuntimeException(e.getMessage(), e);
			}
			if (list == null)
				return null;
			m_ChnlManagerVOs = (FylxdocVo[]) list.toArray(new FylxdocVo[0]);
		}
		Arrays.sort(m_ChnlManagerVOs, 
			new Comparator() {
				public int compare(Object o1, Object o2) {
					String code1 = ((FylxdocVo) o1).getVcostname();
					String code2 = ((FylxdocVo) o2).getVcostname();
					return code1.compareTo(code2);
				}
			}
		);
		return m_ChnlManagerVOs;
	}

}
